﻿@model ZhongheCms.Models.GswTblContent
@{
	ViewBag.Title = "Create";
	Layout = "~/Views/Shared/_Layout.cshtml";
	var strChk = "";
	if (Model.NewFlag > 0)
	{
		strChk = "checked";
	}
	string picsize = "";
	if (!string.IsNullOrEmpty(ViewBag.picsize))
	{
		picsize = "(尺寸:" + ViewBag.picsize + ")";
	}
	picsize = "图片比例4:3";
}
@section css{
	<link rel="stylesheet" href="/Assets/css/datepicker.css" />
	<link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
	<link rel="stylesheet" href="/Assets/webuploader/webuploader.css" />

}
<div class="row">
	<div class="col-xs-12 col-sm-12 widget-container-col">
		@using (Html.BeginForm("Create", "HappyTime", new { id = Model.Id, ViewBag.m, ViewBag.f, ViewBag.p, ViewBag.fid, ViewBag.sdate, ViewBag.edate, ViewBag.keywords,ViewBag.pageIndex }, FormMethod.Post,
			new { name = "myForm", id = "myForm", @class = "form-horizontal", role = "form" }))
		{
			<div class="widget-box">
				<div class="widget-header">
					<h5 class="widget-title">@ViewBag.f  @if (!string.IsNullOrEmpty(ViewBag.p))
														 {
							<span>(@ViewBag.p)</span>
														 }</h5>

					<div class="widget-toolbar">
					</div>
				</div>

				<div class="widget-body">


					<div class="widget-main">

						<div class="form-group">
							<table id="sample-table-1" class="table table-bordered ">
								<tbody>
									<tr>
										<td class="align-right" style="width: 15%; background: #f6f6f6">发布日期
										</td>
										<td>

											<input type="text" id="CreateDate" name="CreateDate" placeholder="" class=" date-picker col-xs-10 col-sm-5" data-date-format="yyyy-mm-dd"  value="@Model.CreateDate.ToShortDateString()" />

										</td>
										<td class="align-right" style="width: 15%; background: #f6f6f6">作者来源
										</td>
										<td>
											<input type="text" name="Author" id="Author" placeholder="作者来源" value="@Model.Author"  class="col-xs-10 col-sm-5 " />
										</td>
									</tr>
									<tr>
										<td class="align-right" style="width: 15%; background: #f6f6f6">主题
										</td>
										<td colspan="3">
											<input  id="ContentTitle" name="ContentTitle" placeholder="主题" type="text" class="form-control" value="@Model.ContentTitle" data-val="true" data-val-required="字段不允许为空" />
											<span class="field-validation-valid help-block" data-valmsg-for="ContentTitle" data-valmsg-replace="true"></span>
										</td>

									</tr>
									<tr>
										<td class="align-right" style="width: 15%; background: #f6f6f6">图片
										</td>
										<td>
											<img width="200" height="100" alt="200x100" id="img" src="@Model.ContentThumb" />


											<div class="btns" style="margin-top: 5px">
												<div id="picker">
													点击选择图片<span>@picsize</span>
												</div>

											</div>
											<input type="hidden" id="ContentThumb" name="ContentThumb" value="@Model.ContentThumb" />
										</td>
										<td class="align-right" style="width: 15%">推荐
										</td>
										<td>
											<input type="checkbox" id="NewFlag" name="NewFlag"  value="1"  @strChk/>
										</td>
									</tr>

							   
									<tr>
										<td class="align-right" style="width: 15%; background: #f6f6f6">内容
										</td>
										<td colspan="3">
											<textarea id="ContentDesc" name="ContentDesc" class="form-control" style="height: 400px">@Model.ContentDesc</textarea>

										</td>
									</tr>
								</tbody>
							</table>
						</div>


						@if (ViewBag.scode == "1")
						{
							<div class="hr hr-2 dotted"></div>
							<div class="alert alert-success">
								<button type="button" class="close" data-dismiss="alert">
									<i class="icon-remove"></i>
								</button>

								<strong>
									<i class="icon-ok"></i>
									提示信息
								</strong>

								信息保存成功!
																
							</div>
						}
						@if (ViewBag.scode == "0")
						{
							<div class="hr hr-2 dotted"></div>
							<div class="alert alert-danger">
								<button type="button" class="close" data-dismiss="alert">
									<i class="icon-remove"></i>
								</button>

								<strong>
									<i class="icon-remove"></i>
									错误提示
								</strong>

								@Html.ValidationSummary(true)

							</div>

						}
						<div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<button class="btn btn-info" type="submit">
									&nbsp;&nbsp;<i class="ace-icon fa fa-check bigger-110"></i>
									保存&nbsp;&nbsp;
								</button>

								&nbsp; &nbsp; &nbsp;
								<button class="btn" type="button" onclick="funBack()">
									&nbsp;&nbsp;<i class="ace-icon fa fa-undo bigger-110"></i>
									返回&nbsp;&nbsp;
								</button>
							</div>
						</div>




					</div>



				</div>

			</div>
		}

	</div>


</div>
@section js{
	<script src="/assets/js/jquery.validate.min.js"></script>
	<script src="/assets/js/jquery.validate.unobtrusive.js"></script>
	<script src="/assets/js/jquery.validate.unobtrusive.bootstrap.js"></script>
	<script src="/assets/js/date-time/bootstrap-datepicker.min.js"></script>
	<script src="/assets/js/date-time/bootstrap-datepicker.zh-CN.js"></script>
	<script charset="utf-8" src="/kindeditor/kindeditor-min.js" type="text/javascript"></script>
	<script charset="utf-8" src="/kindeditor/lang/zh_CN.js" type="text/javascript"></script>
	<script src="/Assets/webuploader/webuploader.js" type="text/javascript"></script>
	<script type="text/javascript">
		KindEditor.ready(function (K) {
			var editor1 = K.create('#ContentDesc', {
				cssPath: '/kindeditor/plugins/code/prettify.css',
				uploadJson: '/kindeditor/upload_json.ashx',
				fileManagerJson: '/kindeditor/file_manager_json.ashx'


			});
			//var editor2 = K.create('#ContentBrief', {
			//    cssPath: '/kindeditor/plugins/code/prettify.css',
			//    uploadJson: '/kindeditor/upload_json.ashx',
			//    fileManagerJson: '/kindeditor/file_manager_json.ashx',
			//    items: [
			//			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			//			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			//			'insertunorderedlist', '|', 'emoticons', 'image', 'link'],


			//});

		});


		jQuery(function ($) {
			//$('.datepick').datepicker({ autoclose: true, format: "yyyy-mm-dd", language: "zh-CN" });
			$('.date-picker').datepicker({
				autoclose: true,
				todayHighlight: true,
				language: "zh-CN"
			});

			var uploader = WebUploader.create({

				resize: true,

				// 自动上传。
				auto: true,

				// swf文件路径
				swf: '/Assets/webuploader/Uploader.swf',

				// 文件接收服务端。
				server: '/GsnService/UploadFileToQiniu/',

				// 选择文件的按钮。可选。
				// 内部根据当前运行是创建，可能是input元素，也可能是flash.
				pick: '#picker'
			});

			// 当有文件添加进来的时候
			//uploader.on('fileQueued', function (file) {
			//    $list.append('<div id="' + file.id + '" class="item">' +
			//    '<h4 class="info">' + file.name + '</h4>' +
			//    '<p class="state">等待上传...</p>' +
			//    '</div>');
			//});

			// 文件上传过程中创建进度条实时显示。
			uploader.on('uploadProgress', function (file, percentage) {
				var $li = $('#' + file.id),
			$percent = $li.find('.progress .progress-bar');
				// 避免重复创建
				if (!$percent.length) {
					$percent = $('<div class="progress progress-striped active">' +
					'<div class="progress-bar" role="progressbar" style="width: 0%">' +
					'</div>' +
					'</div>').appendTo($li).find('.progress-bar');
				}
				$li.find('p.state').text('上传中');

				$percent.css('width', percentage * 100 + '%');
			});
			uploader.on('uploadSuccess', function (file) {
				$('#' + file.id).find('p.state').text('已上传');
			});
			uploader.on('uploadError', function (file) {
				$('#' + file.id).find('p.state').text('上传出错');
			});
			// 完成上传完了，成功或者失败，先删除进度条。
			uploader.on('uploadComplete', function (file) {
				$('#' + file.id).find('.progress').fadeOut();
				//alert(file.name);
			});

			//获取返回值
			uploader.on('uploadAccept', function (file, response) {
				//response.FileName
				//  $('#fName').val(response.FileName);
				$('#ContentThumb').val(response.SavePath + response.SaveName);
				$('#img').attr("src", response.SavePath + response.SaveName);
			});

		});
		function funBack() {
			document.location = "/HappyTime/Index/0?m=@ViewBag.m&f=@ViewBag.f&p=@ViewBag.p&fid=@ViewBag.fid&sdate=@ViewBag.sdate&edate=@ViewBag.edate&keywords=@ViewBag.keywords&pageIndex=@ViewBag.pageIndex";
		}
	</script>
}
